﻿using BLLTarasca;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Tarasca.Models;

namespace Tarasca.Controllers
{
    [Authorize]
    public class ReportesController : Controller
    {
        public ActionResult Index(int idCuenta, int mes, int ano)
        {
            ReportesModel model = new ReportesModel();
            model.Reporte = new BLLReporte().GenerarReporteDeMovimientos(idCuenta, mes, ano);

            List<ReporteItemGrafico> cacona = (from g in model.Reporte.Items
                                               select new ReporteItemGrafico
                                               {
                                                   y = (int) g.Monto,
                                                   indexLabel = g.Categoria.Nombre,
                                                   color = g.Categoria.Color
                                               }).ToList();

            JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
            model.ReporteJSON = jsonSerialiser.Serialize(cacona);

            return PartialView("_Inicio", model);
        }
    }
}
